-
Notifications
You must be signed in to change notification settings - Fork 53
Fix for AudioController.Update() at 2d game tutorial. #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I think there is still an issue with this loop. If you remove an element from the list, you shouldn't increase the index, otherwise you would skip an element.
Alternatively, you can iterate backward to simplify this and have a predictable loop:
|
I think backward iteration is a better solution. public void Update()
{
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
{
SoundEffectInstance instance = _activeSoundEffectInstances[i];
if (instance.State == SoundState.Stopped)
{
if (!instance.IsDisposed)
{
instance.Dispose();
}
_activeSoundEffectInstances.RemoveAt(i);
}
}
} |
Yes, this version would be more preferable, please update @nahaharo |
* fix for AudioController.Update() at 2d game tutorial. * update code with backward iteration --------- Co-authored-by: Hyunwook Ha <hyunwookha@gmail.com>
Fix for the MonoGame/MonoGame#8851
This code fixed two things in AudiroController.Update() at 2D game tutorial.